package com.example.stock.service.impl;

import com.example.stock.mapper.DailyGbStaMapper;
import com.example.stock.model.DailyGBSta;
import com.example.stock.service.DailyGBStaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

@Service
public class DailyGBStaServiceImpl implements DailyGBStaService {

    @Autowired
    DailyGbStaMapper dailyGbStaMapper;

    @Override
    public List<DailyGBSta> getDailyGBStaListByType(String type) {
        return dailyGbStaMapper.getDailyGBStaDataByType(type);
    }

    @Override
    public List<DailyGBSta> getLastUpDailyGBSta(String type, int count) {
        return getDailyGBStaListByType(type).stream().sorted(Comparator.comparing(DailyGBSta::getDate).reversed())
                .filter(i -> i.getDisPct() >= 0)
                .limit(count).toList();
    }

    @Override
    public List<DailyGBSta> getDataByTypeAndDuration(String type, int duration) {
        return dailyGbStaMapper.getDailyGBStaDataByTypeAndDuration(type, duration);
    }
}
